package com.ctshk.sapp.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.BranchOfficeDTO;
import com.ctshk.rpc.cms.req.*;
import com.ctshk.rpc.cms.service.IBaiDuApiService;
import com.ctshk.rpc.cms.service.IBranchOfficeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 分社表 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "分社", tags = "分社")
@RestController
@RequestMapping("/branch-office")
public class BranchOfficeController extends BaseController {

    @DubboReference
    private IBaiDuApiService baiDuApiService;

    @DubboReference
    private IBranchOfficeService branchOfficeService;

    @ApiOperation(value = "获取两个经纬度之间的间距", notes = "获取两个经纬度之间的间距")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/getDistance")
    public Result getDistance(@RequestBody @Valid DistanceQueryReq req) {
        return baiDuApiService.getDistance(req);
    }

    @ApiOperation(value = "获取所有门店并计算当前位置距离门店的距离", notes = "获取所有门店并计算当前位置距离门店的距离")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/query")
    public Result<List<BranchOfficeDTO>> query(@RequestBody @Valid BOQueryReq req) {
        return baiDuApiService.query(req);
    }

    @ApiOperation(value = "新增分社", notes = "新增分社")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/insert")
    public Result insert(@RequestBody @Valid BranchOfficeAddReq req) {
        return branchOfficeService.insert(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询分社", notes = "查询分社")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{branchOfficeId}")
    public Result<BranchOfficeDTO> queryById(@PathVariable("branchOfficeId") String branchOfficeId) {
        return branchOfficeService.queryById(branchOfficeId);
    }

    @ApiOperation(value = "分社分页查询", notes = "分社分页查询")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryList")
    public Result<PageResponse<BranchOfficeDTO>> queryList(@RequestBody @Valid BranchOfficeQueryReq req) {
        return Result.success(branchOfficeService.queryList(req));
    }

    @ApiOperation(value = "分社分页查询（列表）", notes = "分社分页查询（列表）")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryListAll")
    public Result<PageResponse<BranchOfficeDTO>> queryListAll(@RequestBody @Valid BranchOfficeQueryReq req) {
        return Result.success(branchOfficeService.queryListAll(req));
    }

    @ApiOperation(value = "修改分社", notes = "修改分社")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid BranchOfficeUpdateReq req) {
        return branchOfficeService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改有效状态", notes = "修改有效状态")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatusById")
    public Result updateStatusById(@RequestBody @Valid UpdateStatusReq req) {
        return branchOfficeService.updateStatusById(req);
    }
}
